Repository navigation
gh-156953: Fix a reference leak in curses window.insnstr() - #156954
Conversation
insnstr() sets the window rendition before the write. When that fails it released the wide string but not the bytes object that PyCurses_ConvertToString() returned as a new reference, so each failing call leaked one reference to the caller's argument. addstr(), addnstr() and insstr() already release it at the same point.
serhiy-storchaka
left a comment
There was a problem hiding this comment.
LGTM. 👍
It is worth to backport the fix to 3.15, even if we cannot reproduce the leak there.
|
Thanks @fedonman for the PR, and @serhiy-storchaka for merging it 🌮🎉.. I'm working now to backport this PR to: 3.15. |
|
Sorry, @fedonman and @serhiy-storchaka, I could not cleanly backport this to |
…honGH-156954) insnstr() did not release the bytes object it converted its argument to when setting the attributes failed, unlike addstr(), addnstr() and insstr().
|
Thanks @fedonman for the PR, and @serhiy-storchaka for merging it 🌮🎉.. I'm working now to backport this PR to: 3.15. |
|
Sorry, @fedonman and @serhiy-storchaka, I could not cleanly backport this to Please backport manually with cherry_picker, see the devguide for more information. |
|
GH-159108 is a backport of this pull request to the 3.15 branch. |
_curses_window_insnstr_impl()frees the wide string whencurses_wattr_save()orcurses_wattrset()fails, but never decrefs the bytes objectPyCurses_ConvertToString()returned as a new reference, so each failing call leaks one reference to the caller's argument. GH-145609 added that decref toaddstr(),addnstr()andinsstr()and skippedinsnstr(); this adds the missing line and a test covering all four.There is no NEWS entry because no released version can reach the leak: 3.15 has the same omission, but detaching a window arrived with the multi-terminal screen API in GH-151748, so nothing there makes the rendition call fail.
window.insnstr()leaks itsbytesargument when settingattrfails #156953